package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.BFuncPrivilege;

public class BFuncPrivilegeDao extends SuperDao {

	/**
	 * 查询企业的功能权限
	 */
	public List<Object> getFuncPrivilegeByEaId(Long eaId) {
		String hql = "from BFuncPrivilege where eaId = ?";
		return getObject(hql, new Object[] { eaId });
	}

	/**
	 * 根据企业id和功能id查询企业的功能权限
	 */
	public Object getFuncPrivilegeByFuncIdAndEaId(Long eaId, Long funcId) {
		String hql = "from BFuncPrivilege where eaId = ? and functionId = ?";
		List<Object> list = getObject(hql, new Object[] { eaId, funcId });
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}

	/**
	 * 根据功能id查询企业的是否有权限
	 */
	public Long getCountFuncPrivilegeByFuncId(Long eaId, Long funcId) {
		String hql = "select count(id) from BFuncPrivilege where eaId = ? and functionId = ?";
		List<Object> list = getObject(hql, new Object[] { eaId, funcId });
		if (list.isEmpty()) {
			return 0L;
		}

		return (Long) list.get(0);
	}

	/**
	 * 添加企业功能权限
	 */
	public void addFuncPrivilege(BFuncPrivilege funcPrivilege) {
		save(funcPrivilege);
	}

	/**
	 * 删除企业功能权限
	 */
	public void delFuncPrivilege(BFuncPrivilege funcPrivilege) {
		delete(funcPrivilege);
	}

	/**
	 * 通过功能id查询权限信息
	 */
	public List<Object> getFuncPrivilegeByFunctionId(Long functionId) {
		String hql = "from BFuncPrivilege where functionId = ?";
		return getObject(hql, new Object[] { functionId });
	}

	/**
	 * 修改权限标识
	 */
	public void modifyFuncPrivilegeOnOff(BFuncPrivilege funcPrivilege) {
		String sql = "update ubcenter.b_function_privilege set on_off = '"
				+ funcPrivilege.getOnOff() + "' where privilege_id = "
				+ funcPrivilege.getId();
		
		executeUpdate(sql);
	}

}
